<template>
	<view class="user-in-login">
		<!-- 上方文字 -->
		<view class="">
			<view class="login-text-one">欢迎回来</view>
			<view class="login-text-two">Please login to your accounts</view>
		</view>
		<!-- 登录输入信息 -->
		<view class="in-msg">
			<u-form :model="form" ref="uForm">
				<u-form-item label="手机号" prop="mobile"label-width="200rpx">
					<u-input v-model="form.mobile" placeholder="手机号"/>
				</u-form-item>
				<u-form-item label="密码" prop="pass" label-width="200rpx">
					<u-input v-model="form.pass" type="password" placeholder="密码必须以字母开头"/>
				</u-form-item>
			</u-form>
		</view>
		<!-- 忘记密码 -->
		<view class="lost-pass" @click="lostPass">忘记密码?</view>
		<!-- 登录注册 -->
		<view class="login-register">
			<u-button shape="circle" class="login" hover-class="none" @click="submit">登录</u-button>
		</view>	
	</view>
</template>

<script>
	import {postLogin} from "../../../network/login.js"
	
	export default{
		updated() {
				this.$refs.uForm.setRules(this.rules);
		},
		data() {
			return {
					form:{
							mobile:"",
							pass:"",
						},
					rules: {
						mobile: [
							{ 
								required: true, 
								message: '请输入正确手机号', 
								pattern: /^1[3-9]\d{9}$/,
							}
						],
						pass: [
							{
								required: true, 
								pattern:/^[A-Za-z]\w{5,15}$/,
								message: '请输入正确密码', 
							}
						]
					}
			}
		},
		methods:{
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid && this.form.mobile!=="") {
						uni.request({
							url:"http://www.kangliuyong.com:10002/login",
							data:{
								appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
								password: this.form.pass,
								phone: this.form.mobile
							},
							method:"POST",
							header:{"Content-Type":"application/x-www-form-urlencoded"},
							success:(res)=>{
								if(res.data.code==200){
									uni.showToast({
									    title: res.data.msg,
									    duration: 2000,
										icon:'none'
									})
									if(res.data.token){
										uni.setStorageSync('aliToken',res.data.token)
										// getApp().globalData.aliToken = res.data.token
									}
									setTimeout(()=>{
										uni.switchTab({
											url:"../home/Home",
										})
									},2000)
								}else{
									uni.showToast({
										title: res.data.msg,
										duration: 2000,
										icon:'none'
									})
								}
							}
						})
						// postLogin(this.form).then(res=>{
						// 	if(res.data.code==200){
						// 		uni.showToast({
						// 		    title: res.data.msg,
						// 		    duration: 2000,
						// 			icon:'none'
						// 		})
						// 		if(res.data.token){
						// 			uni.setStorageSync('aliToken',res.data.token)
						// 		}
						// 		setTimeout(()=>{
						// 			uni.switchTab({
						// 				url:"../home/Home",
						// 			})
						// 		},2000)
						// 	}else{
						// 		uni.showToast({
						// 			title: res.data.msg,
						// 			duration: 2000,
						// 			icon:'none'
						// 		})
						// 	}
						// })
					}	
				});
			},
			lostPass(){
				uni.navigateTo({
					url:"LostPass"
				})
			}
		},
		
	}
</script>

<style scoped>
	.user-in-login{
		margin: 200rpx 20rpx 0rpx 20rpx;
	}
	.login-text-one{
		font-size: 60rpx;
		font-weight: bold;
		color: #626566;
	}
	.login-text-two{
		font-size: 30rpx;
		margin-top: 60rpx;
		color: #9d9e9e;
	}
	.in-msg{
		margin-top: 60rpx;
	}
	.lost-pass{
		float: right;
		margin-top: 30rpx;
	}
	.login-register{
		width: 100%;
		margin-top: 120rpx;
	}
	.login{
		width: 100%;
		color: #FFFFFF;
		font-size: 30rpx;
		background-color: #0C34BA;
	}
</style>
